<template>
  <div class="WorkingSchedule" v-loading="loading">
    <el-form ref="form" :model="form" label-position="top" class="myform">
      <div>
        <el-form-item label="加工厂" class="myform-item">
          <el-select
            v-model="form.supplier_id"
            placeholder="请选择"

            clearable
          >
            <el-option
              v-for="item in factoryList"
              :key="item.supplier_id"
              :label="item.factory_name"
              :value="item.supplier_id"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="年月" class="myform-item">
          <el-date-picker
            v-model="form.date"
            type="month"
            placeholder="选择月"
            value-format="yyyy-MM"

          ></el-date-picker>
        </el-form-item>
        <el-form-item label="审核状态" class="myform-item">
          <el-select
            v-model="form.status"
            placeholder="请选择"
            clearable
            @keyup.enter.native="onSearch"
          >
            <el-option
              v-for="item in Shoptions"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            ></el-option>
          </el-select>
        </el-form-item>
          <el-form-item label="品牌" class="myform-item">
              <el-select v-model="form.brand_code" placeholder="请选择" @keyup.enter.native="onSearch">
                  <el-option v-for="item in brand_codes" :key="item.value" :label="item.label" :value="item.value"></el-option>
              </el-select>
          </el-form-item>
      </div>
      <div>
        <el-form-item style="margin-top: 50px">
          <el-button type="primary" @click="onSearch">查询</el-button>
        </el-form-item>
      </div>
    </el-form>
    <el-table
      :data="tableData"
      style="width: 100%"
      border
      @selection-change="handleSelectionChange"
    >
      <el-table-column type="selection" width="55" align="center">
      </el-table-column>
      <el-table-column label="加工单号" align="center" prop="so_id">
        <!-- <template slot-scope="{ row }">
          <el-button type="text" @click="onSoid(row.so_id)">
            {{ row.so_id }}</el-button
          >
        </template> -->
      </el-table-column>
      <el-table-column
        label="采购单号"
        align="center"
        prop="po_id"
      ></el-table-column>
      <el-table-column
        label="款号"
        align="center"
        prop="type_no"
      ></el-table-column>
      <el-table-column
        label="数量"
        align="center"
        prop="totalnum"
      ></el-table-column>
      <el-table-column label="审核状态" align="center" prop="status">
        <template slot-scope="{ row }">
          <div
            :style="{
              color:
                row.status == 2 || row.status == 1
                  ? '#67C23A'
                  : row.status == 3
                  ? 'red'
                  : row.status == 0
                  ? '#F7C443'
                  : '',
            }"
          >
            {{
              row.status == 0
                ? "未提交"
                : row.status == 1
                ? "未审核"
                : row.status == 2
                ? "已通过"
                : row.status == 3
                ? "已拒绝"
                : row.status == 4
                ? "已取消"
                : row.status == 5
                ? "已撤回"
                : ""
            }}
          </div>
        </template>
      </el-table-column>
      <el-table-column
        label="成衣大货单价"
        align="center"
        prop="contract_price"
      ></el-table-column>
      <el-table-column
        label="成衣实付单价"
        align="center"
        prop="pay_price"
      ></el-table-column>
      <el-table-column
        label="绣花大货价"
        align="center"
        prop="contract_machining_price"
      ></el-table-column>
      <el-table-column
        label="绣花实付价"
        align="center"
        prop="pay_machining_price"
      ></el-table-column>
      <el-table-column
        label="金额"
        align="center"
        prop="cost_amount"
      ></el-table-column>
      <el-table-column
        label="加工厂"
        align="center"
        prop="factory_name"
      ></el-table-column>
      <el-table-column label="操作" align="center">
        <template slot-scope="{ row }">
          <el-button
            type="text"
            size="default"
            @click="onSoid(row.so_id)"
            >提交更改</el-button
          >
          <!-- <el-button
            type="text"
            size="default"
            v-if="row.status == 1 && row.k_status == 0"
            @click="onPayment(row)"
            >付款</el-button
          > -->
        </template>
      </el-table-column>
    </el-table>
    <el-button type="primary" size="mini" :disabled="!multipleSelection.length" @click="onClickUpdate">价格不变批量提交</el-button>
    <pagination
      :form="form"
      :total="total"
      @paginationPostOrderTaskList="
        postAdminPricingGetPurchaseinListCount_front
      "
    />

  </div>
</template>

<script>
import {
  postAdminPricingGetPurchaseinListCount_front,
  postHomeCodeGetFactory,
  postAdminPricingPiliangsetExaminePricing
} from "@/api";
import { getLastMonth } from "@/utils/time.js";
import pagination from "@/components/pagination.vue";
export default {
  components: { pagination },
  data() {
    return {
      loading: false,
        brand_codes: [
            {label: "十三余", value: "S"},
            {label: "有香", value: "Y"},
            {label: "一弦一木", value: "XM"},
        ],
      Shoptions: [
        {
          label: "未提交",
          value: 0,
        },
        {
          label: "未审核",
          value: 1,
        },
        {
          label: "已通过",
          value: 2,
        },
        {
          label: "已拒绝",
          value: 3,
        },
        {
          label: "已取消",
          value: 4,
        },
      ],
      form: {
        supplier_id: "",
        date: "",
        status: "",
          brand_code: "S",
        type: 0,
        page: 1,
        size: 10,
      },
      factoryList: [],
      tableData: [],
      total: 1,
      multipleSelection: [],
    };
  },
  activated() {
    this.form.date = getLastMonth();
    this.form.status = 0;
    let form = this.form;
    this.postHomeCodeGetFactory();
    this.postAdminPricingGetPurchaseinListCount_front(form);
  },

  methods: {
    async onClickUpdate() {
      let { multipleSelection } = this;
      let arrlist = [];
      for (let index = 0; index < multipleSelection.length; index++) {
        arrlist.push(multipleSelection[index].so_id);
      }
      let obj = {
        arrlist
      }
      await postAdminPricingPiliangsetExaminePricing(obj)
    },
    async onAudit(e){
      let obj = {
        arrlist:[e.so_id]
      }
      await postAdminPricingPiliangsetExaminePricing(obj)
    },
    handleSelectionChange(val) {
      this.multipleSelection = val;
    },
    onSoid(processing_code) {
      this.$router.push({
        name: "ProcessingNuclearPrice",
        query: { processing_code },
      });
    },
    // 加工厂列表
    postHomeCodeGetFactory() {
      let obj = {
        type: 1,
        page: 1,
        size: 10000,
      };
      postHomeCodeGetFactory(obj).then((res) => {
        this.factoryList = res.data;
      });
    },
    // 查看
    onLook(id) {
      this.$router.push({ name: "Contractdetail", query: { id } });
    },

    // 采购列表
    async postAdminPricingGetPurchaseinListCount_front(data) {
      this.loading = true;
      this.form = data;
      // if (data.supplier_id && data.date) {
      if (data.date) {
        postAdminPricingGetPurchaseinListCount_front(data)
          .then((res) => {
            this.loading = false;
            console.log("采购列表", res);
            this.tableData = res.data;
            this.total = Number(res.total);
          })
          .catch((err) => {
            this.loading = false;
          });
      } else {
        this.$message.warning("请选择加工厂和年月");
        this.loading = false;
      }
    },
    // 搜索
    onSearch() {
      this.form.page = 1;
      this.form.size = 10;
      this.postAdminPricingGetPurchaseinListCount_front(this.form);
    },
  },
};
</script>

<style lang="scss" scoped>
.myform {
  display: flex;
  justify-content: space-between;
  > div {
    display: flex;
  }
  &-item {
    margin-right: 10px;
  }
}
.WorkingSchedule {
  background: #ffff;
  padding: 20px;
  border-radius: 2px;
  @include boxShadow;
}
</style>
